/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.urbanski.ksp.kspmultitool.vo;

import com.urbanski.ksp.kspmultitool.ui.Main;
import static com.urbanski.ksp.kspmultitool.util.Constants.G;
//TODO max elevation
/**
 *
 * @author murbanski004
 */
public class Body 
{
    public String name;
    public Body parent;
    public double sma;
    public double e;
    public double inc;
    public double M;
    public int r;
    public double soi;
    public double T;
    public double g;
    public double mu;
    public double rp;
    public double ra;
    public int maxElevation;
    public int flyingLow;
    public double atmosphereHeight;
    public int nearSpace;

    public Body(String name, Body parent, double sma, double e, double inc, double M, int r, double soi, int maxElevation, int flyingLow, double atmosphereHeight, int nearSpace)
    {
        this.name = name;
        this.parent = parent;
        this.sma = sma;
        this.e = e;
        this.inc = inc;
        this.M = M;
        this.r = r;
        this.soi = soi;
        this.maxElevation = maxElevation;
        this.flyingLow = flyingLow;
        this.atmosphereHeight = atmosphereHeight;
        this.nearSpace = nearSpace;
        
        mu = G * M;
        if (sma > 0)
            T = 2 * Math.PI * Math.sqrt(sma * sma * sma / parent.mu);
        g = mu / (r * r);
        rp = (1 - e) * sma;
        ra = (1 + e) * sma;
        
        Main.instance.bodyVariables.put("a_" + name, sma);
        Main.instance.bodyVariables.put("e_" + name, e);
        Main.instance.bodyVariables.put("inc_" + name, inc);
        Main.instance.bodyVariables.put("M_" + name, M);
        Main.instance.bodyVariables.put("r_" + name, Double.valueOf(r));
        Main.instance.bodyVariables.put("soi_" + name, soi);
        Main.instance.bodyVariables.put("mu_" + name, mu);
        Main.instance.bodyVariables.put("T_" + name, T);
        Main.instance.bodyVariables.put("g_" + name, g);
        Main.instance.bodyVariables.put("rp_" + name, rp);
        Main.instance.bodyVariables.put("ra_" + name, ra);
    }

    @Override
    public int hashCode()
    {
        return name.hashCode();
    }

    @Override
    public boolean equals(Object o)
    {
        if (!(o instanceof Body))
            return false;
        final Body other = (Body) o;
        return name.equals(other.name);
    }
    
    @Override
    public String toString()
    {
        return name;
    }
    
    public void printDetails()
    {
        String s = name + ":";
        
        if (parent != null)
        {
            s += "\n\tParent: " + parent.name;
        }
        s += "\n\tSemi-major axis (a): " + sma + " km";
        s += "\n\t\tPeriapsis (rp): " + rp + " km";
        s += "\n\t\tApoapsis (ra): " + ra + " km";
        s += "\n\tOrbital period (T): " + T + " s";
        s += "\n\tEccentricity (e): " + e;
        s += "\n\tInclination (inc): " + inc + " °";
        s += "\n\tMass (M): " + M + " kg";
        s += "\n\tSurface gravity (g): " + g + " m/s²";
        s += "\n\tGravitational parameter (μ): " + mu + " m³/s²";
        s += "\n\tRadius (r): " + r + " m";
        s += "\n\tMax elevation: " + maxElevation + " km";
        s += "\n\tSphere of influence (soi): " + soi + " km";
        s += "\n\tFlying low: 0 km - " + flyingLow + " km";
        s += "\n\tFlying high: " + flyingLow + " km - " + atmosphereHeight + " km";
        s += "\n\tNear space: " + atmosphereHeight + " km - " + nearSpace + " km";
        s += "\n\tOuter space: " + nearSpace + " km - " + soi + " km";
        
        System.out.println(s);
    }
}
